package com.bilibili.juc.cas;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author zuife
 * @description
 * @since 2024-05-02 22:17:55
 */
public class AtomicReferenceDemo {
    public static void main(String[] args) {
        AtomicReference<User> atomicReference = new AtomicReference<>();
        User z3 = new User("z3", 22);
        atomicReference.set(z3);
        System.out.println(atomicReference.compareAndSet(z3, new User("z4", 22)) + "\t" + atomicReference.get().toString());
    }
}

class User {
    String userName;
    int age;

    public User(String userName, int age) {
        this.userName = userName;
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "userName='" + userName + '\'' +
                ", age=";
    }
}
